/*
 *  Copyright 2010 UPF Telecos 4th group G.
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 *
 *       http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *  under the License.
 */

package edu.upf.userinterface.impl;

import edu.upf.content.DescriptionContent;
import edu.upf.core.ClientLogic;
import edu.upf.editor.EditorListModel;
import edu.upf.editor.ImageFilters;
import edu.upf.editor.ImagePanel;
import edu.upf.editor.JAIConvolvePanel;
import edu.upf.editor.JPGsave;
import edu.upf.userinterface.UserInterface;
import edu.upf.utils.Definitions;
import edu.upf.utils.LogSystem;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Date;
import javax.imageio.ImageIO;
import javax.media.jai.PlanarImage;
import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JList;

/**
 * Class that presents a graphical interface for the media sharing software
 * @author netjois
 */
public class GraphicInterface extends JFrame implements UserInterface, Definitions {

    private ClientLogic clientLogic;
    private DefaultListModel contactModel;
    private BufferedImage currentEditorImage;
    private BufferedImage currentFilteredImage;
    private ResultTableModel resultTableModel;
    private DownloadsTableModel downloadsTableModel;
    private LibraryTableModel libraryTableModel;
    private EditorListModel editorListModel;
    private File editedImage;
    private LogSystem log;
    /** 
     * Creates new form GraphicInterface, receives a client logic object for
     * callbacks
     * @param clientLogic
     */
    public GraphicInterface(ClientLogic clientLogic) {
        this.clientLogic=clientLogic;
        contactModel = new DefaultListModel();
        editorListModel=new EditorListModel();
        resultTableModel=new ResultTableModel();
        downloadsTableModel = new DownloadsTableModel();
        libraryTableModel = new LibraryTableModel();
        log=new LogSystem(GraphicInterface.class);

        initComponents();
        initTableModels();
        initMouseListen();
    }

    private void initTableModels(){

        resultTable.setRowHeight(THUMBHEIGHT);
        resultTable.getColumnModel().getColumn(RESULT_THUMB_COLUM).setCellRenderer(new ImageCellRenderer());
        resultTable.getColumnModel().getColumn(RESULT_THUMB_COLUM).setPreferredWidth(THUMBWIDTH);
        resultTable.getColumnModel().getColumn(RESULT_POPUL_COLUMN).setPreferredWidth(THUMBWIDTH);
        resultTable.setColumnSelectionAllowed(false);

        libraryTable.setRowHeight(THUMBHEIGHT);
        libraryTable.getColumnModel().getColumn(LIBRARY_THUMB_COLUM).setCellRenderer(new ImageCellRenderer());
        libraryTable.getColumnModel().getColumn(LIBRARY_THUMB_COLUM).setPreferredWidth(THUMBWIDTH);
        libraryTable.getColumnModel().getColumn(LIBRARY_POPUL_COLUMN).setPreferredWidth(THUMBWIDTH);
        libraryTable.setColumnSelectionAllowed(false);
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jTabbedPane1 = new javax.swing.JTabbedPane();
        mainPanel = new javax.swing.JPanel();
        userField = new javax.swing.JFormattedTextField();
        passField = new javax.swing.JPasswordField();
        connectionIcon = new javax.swing.JLabel();
        jLabel2 = new javax.swing.JLabel();
        jLabel3 = new javax.swing.JLabel();
        loginButton = new javax.swing.JButton();
        statusLabel = new javax.swing.JLabel();
        jCheckBox1 = new javax.swing.JCheckBox();
        jCheckBox2 = new javax.swing.JCheckBox();
        jScrollPane10 = new javax.swing.JScrollPane();
        downloadsTable = new javax.swing.JTable();
        jLabel7 = new javax.swing.JLabel();
        jLabel8 = new javax.swing.JLabel();
        jSeparator4 = new javax.swing.JSeparator();
        libraryPanel = new javax.swing.JPanel();
        jScrollPane8 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel5 = new javax.swing.JLabel();
        jScrollPane9 = new javax.swing.JScrollPane();
        libraryTable = new javax.swing.JTable();
        jButton1 = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jLabel6 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jButton4 = new javax.swing.JButton();
        jButton5 = new javax.swing.JButton();
        jButton6 = new javax.swing.JButton();
        jSeparator6 = new javax.swing.JSeparator();
        chatPanel = new javax.swing.JPanel();
        jScrollPane1 = new javax.swing.JScrollPane();
        contactList = new javax.swing.JList();
        jLabel1 = new javax.swing.JLabel();
        jLabel4 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        eventsLogArea = new javax.swing.JTextArea();
        startChatButton = new javax.swing.JButton();
        jCheckBox3 = new javax.swing.JCheckBox();
        jCheckBox4 = new javax.swing.JCheckBox();
        jSeparator7 = new javax.swing.JSeparator();
        searchPanel = new javax.swing.JPanel();
        basicSearchButton = new javax.swing.JButton();
        jScrollPane3 = new javax.swing.JScrollPane();
        basicSearchArea = new javax.swing.JTextArea();
        basicSearchLabel = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        searchResultLabel = new javax.swing.JLabel();
        categorySearchLabel = new javax.swing.JLabel();
        jScrollPane5 = new javax.swing.JScrollPane();
        OntologyTree = new javax.swing.JTree();
        advancedSearchLabel = new javax.swing.JLabel();
        optionSearchBox = new javax.swing.JComboBox();
        jScrollPane6 = new javax.swing.JScrollPane();
        advancedSearchArea = new javax.swing.JTextArea();
        advancedSearchButton = new javax.swing.JButton();
        jSeparator3 = new javax.swing.JSeparator();
        jScrollPane7 = new javax.swing.JScrollPane();
        categorySearchArea = new javax.swing.JTextArea();
        categorySearchButton = new javax.swing.JButton();
        downloadButton = new javax.swing.JButton();
        jScrollPane4 = new javax.swing.JScrollPane();
        resultTable = new javax.swing.JTable();
        viewButon = new javax.swing.JButton();
        mediaTypeBox = new javax.swing.JComboBox();
        jSeparator8 = new javax.swing.JSeparator();
        editionPanel = new javax.swing.JPanel();
        openEditorButton = new javax.swing.JButton();
        jLabel9 = new javax.swing.JLabel();
        jLabel10 = new javax.swing.JLabel();
        jScrollPane11 = new javax.swing.JScrollPane();
        editList = new javax.swing.JList();
        jLabel11 = new javax.swing.JLabel();
        saveEditorButton = new javax.swing.JButton();
        jSeparator2 = new javax.swing.JSeparator();
        jSeparator5 = new javax.swing.JSeparator();
        imageScrollPane = new javax.swing.JScrollPane();
        controlPanel = new javax.swing.JPanel();
        jLabel12 = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("jMedia");

        jTabbedPane1.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jTabbedPane1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                jTabbedPane1MouseClicked(evt);
            }
        });

        userField.setText("joseluis.grupog");

        passField.setText("gatoupfgroupg");

        connectionIcon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/talk_logo_small.png"))); // NOI18N

        jLabel2.setText("Username");

        jLabel3.setText("Password");

        loginButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/login20px.png"))); // NOI18N
        loginButton.setText("Login");
        loginButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                loginButtonActionPerformed(evt);
            }
        });

        statusLabel.setText("Current status: Disconnected");

        jCheckBox1.setText("Remember me");

        jCheckBox2.setText("Remember password");

        downloadsTable.setModel(downloadsTableModel);
        downloadsTable.setShowHorizontalLines(false);
        downloadsTable.setShowVerticalLines(false);
        jScrollPane10.setViewportView(downloadsTable);

        jLabel7.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel7.setText("Downloads list");

        jLabel8.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel8.setText("Login status");

        jSeparator4.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout mainPanelLayout = new javax.swing.GroupLayout(mainPanel);
        mainPanel.setLayout(mainPanelLayout);
        mainPanelLayout.setHorizontalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLabel8)
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(79, 79, 79)
                                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addGap(14, 14, 14)
                                        .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                            .addComponent(userField, javax.swing.GroupLayout.DEFAULT_SIZE, 144, Short.MAX_VALUE)
                                            .addGroup(mainPanelLayout.createSequentialGroup()
                                                .addGap(38, 38, 38)
                                                .addComponent(jLabel2))
                                            .addComponent(passField)
                                            .addComponent(jCheckBox1)
                                            .addComponent(jCheckBox2)))
                                    .addGroup(mainPanelLayout.createSequentialGroup()
                                        .addGap(56, 56, 56)
                                        .addComponent(jLabel3))))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(121, 121, 121)
                                .addComponent(connectionIcon))
                            .addGroup(mainPanelLayout.createSequentialGroup()
                                .addGap(81, 81, 81)
                                .addComponent(statusLabel))))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addGap(129, 129, 129)
                        .addComponent(loginButton, javax.swing.GroupLayout.PREFERRED_SIZE, 89, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addGap(103, 103, 103)
                .addComponent(jSeparator4, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel7)
                    .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 484, Short.MAX_VALUE))
                .addGap(18, 18, 18))
        );
        mainPanelLayout.setVerticalGroup(
            mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(mainPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(mainPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel7)
                        .addGap(18, 18, 18)
                        .addComponent(jScrollPane10, javax.swing.GroupLayout.DEFAULT_SIZE, 480, Short.MAX_VALUE))
                    .addGroup(mainPanelLayout.createSequentialGroup()
                        .addComponent(jLabel8)
                        .addGap(24, 24, 24)
                        .addComponent(statusLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(connectionIcon)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(userField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(passField, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBox1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jCheckBox2)
                        .addGap(41, 41, 41)
                        .addComponent(loginButton))
                    .addComponent(jSeparator4, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Main Panel", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/jMedia20px.png")), mainPanel); // NOI18N

        jList1.setModel(new javax.swing.AbstractListModel() {
            String[] strings = { "Downloaded", "Cars", "Trip to Rome", "Holidays 2009", "Family" };
            public int getSize() { return strings.length; }
            public Object getElementAt(int i) { return strings[i]; }
        });
        jList1.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        jScrollPane8.setViewportView(jList1);

        jLabel5.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel5.setText("Albums");

        libraryTable.setModel(libraryTableModel);
        libraryTable.setShowHorizontalLines(false);
        libraryTable.setShowVerticalLines(false);
        jScrollPane9.setViewportView(libraryTable);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/new_album.png"))); // NOI18N
        jButton1.setText("New Album");

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/new_media.png"))); // NOI18N
        jButton2.setText("Add media");

        jLabel6.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel6.setText("Media");

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/view.png"))); // NOI18N
        jButton3.setText("View");

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/panel_icons/edition20px.png"))); // NOI18N
        jButton4.setText("Image Edit");

        jButton5.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/annotate.png"))); // NOI18N
        jButton5.setText("Annotate");

        jButton6.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/change_folder.png"))); // NOI18N
        jButton6.setText("Change album");

        jSeparator6.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout libraryPanelLayout = new javax.swing.GroupLayout(libraryPanel);
        libraryPanel.setLayout(libraryPanelLayout);
        libraryPanelLayout.setHorizontalGroup(
            libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(libraryPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(libraryPanelLayout.createSequentialGroup()
                        .addComponent(jButton1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jButton2))
                    .addComponent(jScrollPane8, javax.swing.GroupLayout.PREFERRED_SIZE, 231, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel5))
                .addGap(18, 18, 18)
                .addComponent(jSeparator6, javax.swing.GroupLayout.PREFERRED_SIZE, 14, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(libraryPanelLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 578, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(libraryPanelLayout.createSequentialGroup()
                        .addComponent(jButton3)
                        .addGap(18, 18, 18)
                        .addComponent(jButton4)
                        .addGap(18, 18, 18)
                        .addComponent(jButton5)
                        .addGap(18, 18, 18)
                        .addComponent(jButton6)
                        .addGap(172, 172, 172))
                    .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 619, Short.MAX_VALUE))
                .addGap(12, 12, 12))
        );
        libraryPanelLayout.setVerticalGroup(
            libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(libraryPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(libraryPanelLayout.createSequentialGroup()
                        .addComponent(jLabel6)
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane9, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton3)
                            .addComponent(jButton4)
                            .addComponent(jButton5)
                            .addComponent(jButton6)))
                    .addComponent(jSeparator6, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addGroup(libraryPanelLayout.createSequentialGroup()
                        .addComponent(jLabel5)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane8, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(libraryPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jButton1)
                            .addComponent(jButton2))))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Media library", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/library20px.png")), libraryPanel); // NOI18N

        contactList.setModel(contactModel);
        jScrollPane1.setViewportView(contactList);

        jLabel1.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel1.setText("Contact list");

        jLabel4.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel4.setText("Latest events");

        eventsLogArea.setBackground(new java.awt.Color(253, 251, 227));
        eventsLogArea.setColumns(20);
        eventsLogArea.setEditable(false);
        eventsLogArea.setRows(5);
        jScrollPane2.setViewportView(eventsLogArea);

        startChatButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/chat20px.png"))); // NOI18N
        startChatButton.setText("Start chat");
        startChatButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                startChatButtonActionPerformed(evt);
            }
        });

        jCheckBox3.setSelected(true);
        jCheckBox3.setText("Show system events");

        jCheckBox4.setSelected(true);
        jCheckBox4.setText("Show messaging events");

        jSeparator7.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout chatPanelLayout = new javax.swing.GroupLayout(chatPanel);
        chatPanel.setLayout(chatPanelLayout);
        chatPanelLayout.setHorizontalGroup(
            chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chatPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel1)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addGap(94, 94, 94)
                        .addComponent(startChatButton, javax.swing.GroupLayout.PREFERRED_SIZE, 119, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(jScrollPane1, javax.swing.GroupLayout.PREFERRED_SIZE, 325, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(12, 12, 12)
                .addComponent(jSeparator7, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLabel4)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addComponent(jCheckBox4)
                        .addGap(18, 18, 18)
                        .addComponent(jCheckBox3))
                    .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE))
                .addContainerGap())
        );
        chatPanelLayout.setVerticalGroup(
            chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(chatPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addGroup(chatPanelLayout.createSequentialGroup()
                                .addComponent(jLabel1)
                                .addGap(12, 12, 12)
                                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 442, Short.MAX_VALUE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(startChatButton))
                            .addComponent(jSeparator7, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE))
                        .addContainerGap())
                    .addGroup(chatPanelLayout.createSequentialGroup()
                        .addComponent(jLabel4)
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 438, Short.MAX_VALUE)
                        .addGap(18, 18, 18)
                        .addGroup(chatPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jCheckBox4)
                            .addComponent(jCheckBox3))
                        .addGap(20, 20, 20))))
        );

        jTabbedPane1.addTab("Chat", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/chat20px.png")), chatPanel); // NOI18N

        basicSearchButton.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        basicSearchButton.setText("Search");
        basicSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                basicSearchButtonActionPerformed(evt);
            }
        });

        basicSearchArea.setColumns(15);
        basicSearchArea.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        basicSearchArea.setRows(1);
        jScrollPane3.setViewportView(basicSearchArea);

        basicSearchLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        basicSearchLabel.setText("Basic search");

        searchResultLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        searchResultLabel.setText("Search results");

        categorySearchLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        categorySearchLabel.setText("Category search");

        javax.swing.tree.DefaultMutableTreeNode treeNode1 = new javax.swing.tree.DefaultMutableTreeNode("Categories");
        javax.swing.tree.DefaultMutableTreeNode treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("colors");
        javax.swing.tree.DefaultMutableTreeNode treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("blue");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("violet");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("red");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("yellow");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("sports");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("basketball");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("soccer");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("football");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("hockey");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        treeNode2 = new javax.swing.tree.DefaultMutableTreeNode("food");
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("hot dogs");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("pizza");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("ravioli");
        treeNode2.add(treeNode3);
        treeNode3 = new javax.swing.tree.DefaultMutableTreeNode("bananas");
        treeNode2.add(treeNode3);
        treeNode1.add(treeNode2);
        OntologyTree.setModel(new javax.swing.tree.DefaultTreeModel(treeNode1));
        jScrollPane5.setViewportView(OntologyTree);

        advancedSearchLabel.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        advancedSearchLabel.setText("News search");

        optionSearchBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Search in paragraph", "Search in title", "Search in article" }));

        advancedSearchArea.setColumns(15);
        advancedSearchArea.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        advancedSearchArea.setRows(1);
        jScrollPane6.setViewportView(advancedSearchArea);

        advancedSearchButton.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        advancedSearchButton.setText("Search");
        advancedSearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                advancedSearchButtonActionPerformed(evt);
            }
        });

        categorySearchArea.setColumns(14);
        categorySearchArea.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        categorySearchArea.setRows(1);
        jScrollPane7.setViewportView(categorySearchArea);

        categorySearchButton.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        categorySearchButton.setText("Search");
        categorySearchButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                categorySearchButtonActionPerformed(evt);
            }
        });

        downloadButton.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/download.png"))); // NOI18N
        downloadButton.setText("Download");
        downloadButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                downloadButtonActionPerformed(evt);
            }
        });

        resultTable.setBackground(new java.awt.Color(254, 254, 254));
        resultTable.setModel(resultTableModel);
        resultTable.setGridColor(new java.awt.Color(254, 254, 254));
        resultTable.setIntercellSpacing(new java.awt.Dimension(0, 0));
        resultTable.setSelectionBackground(new java.awt.Color(217, 217, 217));
        resultTable.setSelectionForeground(new java.awt.Color(1, 1, 1));
        resultTable.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        resultTable.setShowHorizontalLines(false);
        resultTable.setShowVerticalLines(false);
        jScrollPane4.setViewportView(resultTable);

        viewButon.setIcon(new javax.swing.ImageIcon(getClass().getResource("/button_icons/view.png"))); // NOI18N
        viewButon.setText("View");

        mediaTypeBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "All", "Image", "Video" }));

        jSeparator8.setOrientation(javax.swing.SwingConstants.VERTICAL);

        javax.swing.GroupLayout searchPanelLayout = new javax.swing.GroupLayout(searchPanel);
        searchPanel.setLayout(searchPanelLayout);
        searchPanelLayout.setHorizontalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(categorySearchLabel)
                    .addComponent(optionSearchBox, javax.swing.GroupLayout.PREFERRED_SIZE, 193, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(advancedSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addComponent(advancedSearchLabel)
                    .addComponent(mediaTypeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, searchPanelLayout.createSequentialGroup()
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(basicSearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 116, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addComponent(basicSearchLabel, javax.swing.GroupLayout.Alignment.LEADING))
                    .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.Alignment.LEADING)
                        .addComponent(jSeparator3, javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, searchPanelLayout.createSequentialGroup()
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 197, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                            .addComponent(categorySearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 110, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jSeparator8, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(searchResultLabel)
                        .addGap(330, 330, 330))
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(viewButon, javax.swing.GroupLayout.PREFERRED_SIZE, 72, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(downloadButton))
                    .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 516, Short.MAX_VALUE))
                .addContainerGap())
        );
        searchPanelLayout.setVerticalGroup(
            searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(searchPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(searchResultLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane4, javax.swing.GroupLayout.DEFAULT_SIZE, 443, Short.MAX_VALUE)
                        .addGap(11, 11, 11)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(viewButon)
                            .addComponent(downloadButton)))
                    .addComponent(jSeparator8, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE)
                    .addGroup(searchPanelLayout.createSequentialGroup()
                        .addComponent(basicSearchLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(basicSearchButton, 0, 0, Short.MAX_VALUE)
                            .addComponent(jScrollPane3, javax.swing.GroupLayout.PREFERRED_SIZE, 25, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addGap(11, 11, 11)
                        .addComponent(mediaTypeBox, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jSeparator1, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(advancedSearchLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(advancedSearchButton, 0, 0, Short.MAX_VALUE)
                            .addComponent(jScrollPane6, javax.swing.GroupLayout.PREFERRED_SIZE, 24, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(optionSearchBox, javax.swing.GroupLayout.PREFERRED_SIZE, 27, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jSeparator3, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(categorySearchLabel)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(searchPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(categorySearchButton, javax.swing.GroupLayout.PREFERRED_SIZE, 26, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane5, javax.swing.GroupLayout.DEFAULT_SIZE, 208, Short.MAX_VALUE)))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Search", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/search20px.png")), searchPanel); // NOI18N

        openEditorButton.setText("Open");
        openEditorButton.setName("openEditorButton"); // NOI18N
        openEditorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                openEditorButtonActionPerformed(evt);
            }
        });

        jLabel9.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel9.setText("Actions");

        jLabel10.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel10.setText("Filters");

        editList.setModel(editorListModel);
        editList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
        editList.addListSelectionListener(new javax.swing.event.ListSelectionListener() {
            public void valueChanged(javax.swing.event.ListSelectionEvent evt) {
                editListValueChanged(evt);
            }
        });
        jScrollPane11.setViewportView(editList);

        jLabel11.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel11.setText("Image info");

        saveEditorButton.setText("Save");
        saveEditorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                saveEditorButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout editionPanelLayout = new javax.swing.GroupLayout(editionPanel);
        editionPanel.setLayout(editionPanelLayout);
        editionPanelLayout.setHorizontalGroup(
            editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, editionPanelLayout.createSequentialGroup()
                            .addComponent(openEditorButton)
                            .addGap(18, 18, 18)
                            .addComponent(saveEditorButton)
                            .addGap(100, 100, 100))
                        .addComponent(jLabel9)
                        .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addComponent(jScrollPane11, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, 190, Short.MAX_VALUE)
                            .addComponent(jSeparator5, javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jSeparator2, javax.swing.GroupLayout.Alignment.LEADING)))
                    .addComponent(jLabel11)
                    .addComponent(jLabel10))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(imageScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 677, Short.MAX_VALUE)
                .addContainerGap())
        );
        editionPanelLayout.setVerticalGroup(
            editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(editionPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(editionPanelLayout.createSequentialGroup()
                        .addComponent(jLabel9)
                        .addGap(12, 12, 12)
                        .addGroup(editionPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(openEditorButton)
                            .addComponent(saveEditorButton))
                        .addGap(12, 12, 12)
                        .addComponent(jSeparator2, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel11)
                        .addGap(55, 55, 55)
                        .addComponent(jSeparator5, javax.swing.GroupLayout.PREFERRED_SIZE, 10, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(jLabel10)
                        .addGap(12, 12, 12)
                        .addComponent(jScrollPane11, javax.swing.GroupLayout.DEFAULT_SIZE, 312, Short.MAX_VALUE))
                    .addComponent(imageScrollPane, javax.swing.GroupLayout.DEFAULT_SIZE, 515, Short.MAX_VALUE))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Image edition", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/edition20px.png")), editionPanel); // NOI18N

        jLabel12.setFont(new java.awt.Font("DejaVu Sans", 0, 14));
        jLabel12.setText("Section");

        javax.swing.GroupLayout controlPanelLayout = new javax.swing.GroupLayout(controlPanel);
        controlPanel.setLayout(controlPanelLayout);
        controlPanelLayout.setHorizontalGroup(
            controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addContainerGap())
        );
        controlPanelLayout.setVerticalGroup(
            controlPanelLayout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(controlPanelLayout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel12)
                .addContainerGap(510, Short.MAX_VALUE))
        );

        jTabbedPane1.addTab("Control Panel", new javax.swing.ImageIcon(getClass().getResource("/panel_icons/configuration20px.png")), controlPanel); // NOI18N

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 913, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 573, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jTabbedPane1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jTabbedPane1MouseClicked

}//GEN-LAST:event_jTabbedPane1MouseClicked

    private void downloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_downloadButtonActionPerformed

        clientLogic.downloadContent(resultTable.getSelectedRow());
}//GEN-LAST:event_downloadButtonActionPerformed

    private void categorySearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_categorySearchButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_categorySearchButtonActionPerformed

    private void advancedSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_advancedSearchButtonActionPerformed
        // TODO add your handling code here:
}//GEN-LAST:event_advancedSearchButtonActionPerformed

    private void basicSearchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_basicSearchButtonActionPerformed
        String subtype=((String)mediaTypeBox.getSelectedItem()).toLowerCase();
        clientLogic.sendSearchQuery(BASIC,subtype,basicSearchArea.getText());
}//GEN-LAST:event_basicSearchButtonActionPerformed

    private void startChatButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_startChatButtonActionPerformed
        startChatWith(getSelectedUser());
}//GEN-LAST:event_startChatButtonActionPerformed

    private void loginButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_loginButtonActionPerformed

        String test = loginButton.getText();
        if (test.equals("Login")) {
            clientLogic.login(userField.getText().toString().trim(),
                    new String(passField.getPassword()).trim(),JMEDIA_RESOURCE);
        } else if (test.equals("Logout")) {
            clientLogic.logout();
        } else if(test.equals("Cancel")){
            clientLogic.interruptLogin();
        }
}//GEN-LAST:event_loginButtonActionPerformed

    private void openEditorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_openEditorButtonActionPerformed

        JFileChooser openFileChooser = new JFileChooser();
        openFileChooser.setAcceptAllFileFilterUsed(false);
        ImageFilters imageFilters= new ImageFilters();
        openFileChooser.addChoosableFileFilter(imageFilters.getPNGFilter());
        openFileChooser.addChoosableFileFilter(imageFilters.getGIFFilter());
        openFileChooser.addChoosableFileFilter(imageFilters.getJPGFilter());
        int returnVal = openFileChooser.showOpenDialog(this);
        if (returnVal == JFileChooser.APPROVE_OPTION) {
            File file = openFileChooser.getSelectedFile();
            try{
                currentEditorImage=ImageIO.read(file);
                showEditImage(currentEditorImage);
            }catch(IOException ex){
                log.addInfoLog(ex.getMessage()+"Error while attempting to load the image");
            }
        }
}//GEN-LAST:event_openEditorButtonActionPerformed

    private void editListValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_editListValueChanged

        if (evt.getValueIsAdjusting()) {
            return;
        }

        JList theList = (JList) evt.getSource();
            // picture.setIcon(null);
        if (!theList.isSelectionEmpty()) {
            int index = theList.getSelectedIndex();
            PlanarImage resultPlanarImage = (new JAIConvolvePanel().
                    convolve(PlanarImage.wrapRenderedImage(currentEditorImage), index));
            currentFilteredImage = resultPlanarImage.getAsBufferedImage();
            showEditImage(currentFilteredImage);
        }
    }//GEN-LAST:event_editListValueChanged

    private void saveEditorButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_saveEditorButtonActionPerformed
        //Container actual = this.getContentPane();
        //String contname = actual.getName();
        // if (contname.equals(file.getName())) { //if the panel has the image, then we can save.
        JFileChooser saveFileChooser = new JFileChooser();
        // Start in current directory
        saveFileChooser.setCurrentDirectory(new File("."));
        // Set filter for Java source files.
        saveFileChooser.setAcceptAllFileFilterUsed(false);
        ImageFilters imageFilters= new ImageFilters();
        saveFileChooser.addChoosableFileFilter(imageFilters.getJPGFilter());
        // Set to a default name for save.
        editedImage = new File("editedImage.jpg");
        saveFileChooser.setSelectedFile(editedImage);

        // Open chooser dialog
        int result = saveFileChooser.showSaveDialog(this);
        if (result == JFileChooser.APPROVE_OPTION) {
            editedImage = saveFileChooser.getSelectedFile();
            ImageQualityDialog imageQualityDialog = new ImageQualityDialog(this,true);
            imageQualityDialog.setVisible(true);
        }
    }//GEN-LAST:event_saveEditorButtonActionPerformed

    public void showEditImage(BufferedImage img){
         ImagePanel ip = new ImagePanel(img);
         imageScrollPane.getViewport().add(ip);
    }

    public void saveEditImage(int quality) throws FileNotFoundException, IOException{
        float value = (float)quality/100.0f;
        new JPGsave(editedImage,PlanarImage.wrapRenderedImage(currentFilteredImage), value);
    }

    @Override
    public void updateState(int state){
        if(state==LOGGED_STATE){
            connectionIcon.setIcon(new ImageIcon(getClass().getResource("/logo_con.png")));
            statusLabel.setText("Current Status: Connected");
            loginButton.setText("Logout");
        }else if(state==LOGGING_STATE){
            connectionIcon.setIcon(new ImageIcon(getClass().getResource("/loading.gif")));
            statusLabel.setText("Current Status: Connecting...");
            loginButton.setText("Cancel");
        }
        else{
            connectionIcon.setIcon(new ImageIcon(getClass().getResource("/talk_logo_small.png")));
            statusLabel.setText("Current Status: Disconnected");
            loginButton.setText("Login");
        }
    }

    @Override
    public void addUserToList(String user){
        contactModel.addElement(user);
    }

    @Override
    public void removeUserFromList(String user){
        contactModel.removeElement(user);
    }

    @Override
    public void addResult(DescriptionContent receivedContent){
        resultTableModel.addDescriptionContent(receivedContent);
    }

    @Override
    public void clearResults(){
        int rowNumber=0;
        rowNumber= resultTable.getRowCount();
        for(int i=0; i<rowNumber;i++){
            resultTableModel.removeDescriptionContentAt(0);
        }
    }

    private void initMouseListen(){
        MouseListener mouseListener = new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if(e.getClickCount()==2) {
                    if(getSelectedUser()!=null){
                        startChatWith(getSelectedUser());
                    }
                }
            }
        };
        contactList.addMouseListener(mouseListener);
    }

    private String getSelectedUser(){
        int currentListPosition = contactList.getAnchorSelectionIndex();
        if (currentListPosition!=-1){
            return clientLogic.getUserMail(currentListPosition);
        }
        return null;
    }

    @Override
    public void startChatWith(String user){
        clientLogic.openUserChat(user);
    }

    @Override
    public void userLog(String log){
        eventsLogArea.append(new Date()+": "+log+"\n");
    }

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JTree OntologyTree;
    private javax.swing.JTextArea advancedSearchArea;
    private javax.swing.JButton advancedSearchButton;
    private javax.swing.JLabel advancedSearchLabel;
    private javax.swing.JTextArea basicSearchArea;
    private javax.swing.JButton basicSearchButton;
    private javax.swing.JLabel basicSearchLabel;
    private javax.swing.JTextArea categorySearchArea;
    private javax.swing.JButton categorySearchButton;
    private javax.swing.JLabel categorySearchLabel;
    private javax.swing.JPanel chatPanel;
    private javax.swing.JLabel connectionIcon;
    private javax.swing.JList contactList;
    private javax.swing.JPanel controlPanel;
    private javax.swing.JButton downloadButton;
    private javax.swing.JTable downloadsTable;
    private javax.swing.JList editList;
    private javax.swing.JPanel editionPanel;
    private javax.swing.JTextArea eventsLogArea;
    private javax.swing.JScrollPane imageScrollPane;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JButton jButton5;
    private javax.swing.JButton jButton6;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JCheckBox jCheckBox2;
    private javax.swing.JCheckBox jCheckBox3;
    private javax.swing.JCheckBox jCheckBox4;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel12;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane10;
    private javax.swing.JScrollPane jScrollPane11;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JScrollPane jScrollPane3;
    private javax.swing.JScrollPane jScrollPane4;
    private javax.swing.JScrollPane jScrollPane5;
    private javax.swing.JScrollPane jScrollPane6;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JScrollPane jScrollPane8;
    private javax.swing.JScrollPane jScrollPane9;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JSeparator jSeparator3;
    private javax.swing.JSeparator jSeparator4;
    private javax.swing.JSeparator jSeparator5;
    private javax.swing.JSeparator jSeparator6;
    private javax.swing.JSeparator jSeparator7;
    private javax.swing.JSeparator jSeparator8;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JPanel libraryPanel;
    private javax.swing.JTable libraryTable;
    private javax.swing.JButton loginButton;
    private javax.swing.JPanel mainPanel;
    private javax.swing.JComboBox mediaTypeBox;
    private javax.swing.JButton openEditorButton;
    private javax.swing.JComboBox optionSearchBox;
    private javax.swing.JPasswordField passField;
    private javax.swing.JTable resultTable;
    private javax.swing.JButton saveEditorButton;
    private javax.swing.JPanel searchPanel;
    private javax.swing.JLabel searchResultLabel;
    private javax.swing.JButton startChatButton;
    private javax.swing.JLabel statusLabel;
    private javax.swing.JFormattedTextField userField;
    private javax.swing.JButton viewButon;
    // End of variables declaration//GEN-END:variables
}
